import request from './index'
import type { ApiResponse } from './user'

// 看板分组
export interface DashboardGroup {
  id: string
  name: string
  count: number
}

// 看板项
export interface Dashboard {
  id: string
  title: string
  description: string
  groupId: string
  thumbnail: string
  charts?: Chart[]
}

// 图表定义
export interface Chart {
  id: string
  title: string
  type: string
  options: any
}

// 获取看板分组
export function getDashboardGroups(): Promise<ApiResponse<DashboardGroup[]>> {
  return request({
    url: '/api/dashboard/groups',
    method: 'get'
  })
}

// 获取看板列表
export function getDashboardList(params?: { groupId?: string, keyword?: string }): Promise<ApiResponse<Dashboard[]>> {
  return request({
    url: '/api/dashboard/list',
    method: 'get',
    params
  })
}

// 获取看板详情
export function getDashboardDetail(id: string): Promise<ApiResponse<Dashboard>> {
  return request({
    url: '/api/dashboard/detail',
    method: 'get',
    params: { id }
  })
}

// 创建看板
export function createDashboard(data: { title: string, groupId: string, description?: string }): Promise<ApiResponse<Dashboard>> {
  return request({
    url: '/api/dashboard/create',
    method: 'post',
    data
  })
}

// 保存看板
export function saveDashboard(data: { id: string, charts: Chart[] }): Promise<ApiResponse<{ id: string, charts: Chart[] }>> {
  return request({
    url: '/api/dashboard/save',
    method: 'post',
    data
  })
}

// 创建看板分组
export function createDashboardGroup(data: { name: string }): Promise<ApiResponse<DashboardGroup>> {
  return request({
    url: '/api/dashboard/group/create',
    method: 'post',
    data
  })
} 